package com.viknix.threadpool.manager.common.model;

import com.viknix.threadpool.manager.common.config.PoolParamterInfoGroupSequenceProvider;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.group.GroupSequenceProvider;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @Author: Dongqi
 * @Date: 2021/10/29 11:24
 * @Version 1.0
 * @Description: 客户端与服务端配置信息传输对象
 */
@GroupSequenceProvider(PoolParamterInfoGroupSequenceProvider.class)
@Data
@Accessors(chain = true)
public class PoolParameterInfo implements Serializable {

    private static final long serialVersionUID = -7123935122108553864L;

    private transient Long threadPoolInfoId;

    @NotBlank(message = "命名空间不能为空！")
    private String namespace;

    @NotBlank(message = "项目id不能为空！")
    private String item;

    @NotBlank(message = "线程池id不能为空！")
    private String threadPoolId;

    @Min(value = 0, message = "核心线程数不能小于0！")
    @NotNull(message = "核心线程数不能为空")
    private Integer corePoolSize;

    @Min(value = 1, message = "最大线程数不能小于0！")
    @NotNull(message = "最大线程数不能为空！")
    private Integer maxPoolSize;

    @NotNull(message = "队列类型不能为空！")
    private Integer queueType;

    @NotNull(message = "队列容量不能为空！")
    private Integer capacity;

    @NotNull(message = "拒绝策略类型不能为空！")
    private Integer rejectedType;

    @NotNull(message = "keepAliveTime 不能为空！")
    private Integer keepAliveTime;

    /**
     * 是否报警 0：不报警 1:报警
     * 默认不开启
     */
    private Integer isAlert = 1;

    @NotNull(message = "容量告警阈值不能为空！", groups = Alert.class)
    @Range(min = 0, max = 100, message = "告警阈值为0 ~ 100！")
    private Integer capacityAlert;

    @NotNull(message = "活跃度告警阈值不能为空！", groups = Alert.class)
    @Range(min = 0, max = 100, message = "告警阈值为0 ~ 100！")
    private Integer livenessAlert;

    private transient String content;

    public boolean alert() {
        if (isAlert == null) {
            return true;
        }
        return isAlert == 0 ? false : true;
    }

    public interface Alert {
    }
}
